//
//  NewHomeHeaderView.m
//  NewPro
//
//  Created by RYX on 2019/4/18.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewHomeHeaderView.h"
#import "NewHomeMenuView.h"
#import "NewHomeNewsView.h"
#import "NewHomeSliderView.h"
#import "NewHomeDataView.h"
#import "NewHomeServiceView.h"
#import "NewHomeSectionHeaderView.h"
#import "NewHomeModel.h"
#import "HomeBanner1.h"
#import "HomeBanner2.h"
#import "ScanIDCardFontViewController.h"
#import "HomeList.h"

#import "HostRecommendView.h"

@interface NewHomeHeaderView ()<NewHomeImgViewDelegate,NewHomeMenuViewDelegate,NewHomeSliderViewDelegate,NewHomeDataViewDelegate,NewHomeServiceViewDelegate,NewHomeSectionHeaderViewDelegate,HostRecommendViewDelegate>

@property (nonatomic,weak) NewHomeMenuView *menuView;
@property (nonatomic,weak) NewHomeNewsView *newsView;
@property (nonatomic,weak) NewHomeSliderView *sliderView;
@property (nonatomic,strong) NewHomeDataView *dataView;
@property (nonatomic,strong) NewHomeServiceView *serviceView;
@property (nonatomic,strong) NewHomeSectionHeaderView *sectionView;
@property (nonatomic,strong) HostRecommendView *hostView;
@end

@implementation NewHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = BASECOLOR;
        [self setUI];
    }
    return self;
}

- (void)setUI{
 
    NewHomeImgView *imgView = [[NewHomeImgView alloc] init];
    imgView.delegate = self;
    self.imgView = imgView;
    [self addSubview:imgView];
    
    NewHomeMenuView *menuView = [[NewHomeMenuView alloc] init];
    menuView.delegate = self;
    self.menuView = menuView;
    [self addSubview:menuView];
    
    NewHomeNewsView *newsView = [[NewHomeNewsView alloc] init];
    self.newsView = newsView;
    [self addSubview:newsView];
    
    NewHomeSliderView *sliderView = [[NewHomeSliderView alloc] init];
    sliderView.delegate = self;
    self.sliderView = sliderView;
    [self addSubview:sliderView];
    
    NewHomeDataView *dataView = [[NewHomeDataView alloc] init];
    dataView.delegate = self;
    self.dataView = dataView;
    [self addSubview:dataView];
    
    NewHomeServiceView *serviceView = [[NewHomeServiceView alloc] init];
    serviceView.delegate = self;
    self.serviceView = serviceView;
    [self addSubview:serviceView];
    
    NewHomeSectionHeaderView *sectionView = [[NewHomeSectionHeaderView alloc] init];
    sectionView.delegate = self;
    self.sectionView = sectionView;
    [self addSubview:sectionView];
    
    HostRecommendView *hostView = [[HostRecommendView alloc] init];
    hostView.delegate = self;
    self.hostView = hostView;
    [self addSubview:hostView];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(328);
    }];
    
    [menuView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self);
        make.top.equalTo(imgView.mas_bottom);
        make.height.mas_equalTo(140);
    }];
    
    [newsView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self);
        make.top.equalTo(menuView.mas_bottom).offset(0.5);
        make.height.mas_equalTo(43);
    }];
    
    [sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self);
        make.top.equalTo(newsView.mas_bottom).offset(10);
        make.height.mas_equalTo(117);
    }];
    
    [dataView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self);
        make.top.equalTo(sliderView.mas_bottom).offset(10);
        make.height.mas_equalTo(182);
    }];
    
    [serviceView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self);
        make.top.equalTo(dataView.mas_bottom).offset(10);
        make.height.mas_equalTo(143.5);
    }];
    
    CGFloat host_width = (ScreenWidth - 28) * 0.4 + 10 + 37;
    [hostView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.right.equalTo(self);
        make.top.equalTo(serviceView.mas_bottom).offset(10);
        make.height.mas_equalTo(host_width);
    }];
    
    [sectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self);
        make.top.equalTo(hostView.mas_bottom).offset(10);
        make.bottom.equalTo(self);
    }];
    
}

- (void)setModel:(NewHomeModel *)model{
    
    HomeBanner1 *banner1 = [HomeBanner1 mj_objectWithKeyValues:model.banner1.firstObject];
    self.imgView.model = banner1;
    
    self.newsView.listArr = model.headlines;
    
    self.dataView.model = model.monsy;

    self.sliderView.listArr = model.banner2;
    
}

#pragma mark - NewHomeImgViewDelegate,NewHomeMenuViewDelegate,NewHomeSliderViewDelegate,NewHomeDataViewDelegate,NewHomeServiceViewDelegate,NewHomeSectionHeaderViewDelegate
- (void)judgeIfHadRealName{
    
    NSString *flag = [HomeList sharedInstance].hadRealName;
    NSString *mes = @"您尚未进行实名认证";
    NSString *title = @"前往认证";
    if ([flag isEqualToString:@"2"]) {
        
        mes = @"您已提交实名认证，请耐心等待审核";
        title = @"前往修改";
    }
    
    if ([flag isEqualToString:@"3"]) {
        
        mes = @"实名认证未通过，请重新实名认证";
        title = @"重新认证";
    }
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:mes preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    MJWeakSelf
    [alert addAction:[UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        ScanIDCardFontViewController *VC = [[ScanIDCardFontViewController alloc] init];
        [VC setHidesBottomBarWhenPushed:YES];
        [[weakSelf getCurrentViewController].navigationController pushViewController:VC animated:YES];
        
    }]];
    [[self getCurrentViewController] presentViewController:alert animated:YES completion:^{
        
    }];
}

- (void)setCreditCardListArr:(NSArray *)creditCardListArr{
    
    self.hostView.listArr = creditCardListArr;
}
@end
